import corejuliano.designpattern.mvc.*;
import corejuliano.gameelement.*;
import flash.geom.*;

class corejuliano.gameelement.Tile
{
	private var tileables:Array;
	private var position:Point;
	private var depth:Number;
	private var area:Rectangle;	
	private var ocupedArea:Rectangle;
	
	public function Tile()
	{
		tileables = new Array(); 
	}
	
	public function addTileable(tileable:Tileable):Void
	{
		tileables.push(tileable);
	}	
	
	public function removeTileable(tileable:Tileable):Void
	{
		for(var i:Number = tileables.length -1; i >= 0; i--)
			if (tileables[i] == tileable)
				tileables.slice(i,1);
	}
	
	public function isSolid():Boolean
	{
		for (var i:Number = 0; i < getTileables().length; i++)
			if (getTileables()[i].isSolid())
				return true;		
		return false;		
	}
	
	public function getTileables():Array
	{
		return tileables;
	}
		
	public function destroy():Void
	{
		for (var i:Number = 0; i < getTileables().length; i++)
			removeTileable(getTileables()[i]);
	}

	public function getPosition():Point
	{
		return position;
	}

	public function setPosition(position:Point):Void
	{
		this.position = position;
	}
	
	public function setDepth(depth:Number):Void
	{
		this.depth = depth;
	}

	public function getDepth():Number
	{
		return depth;
	}

	public function getArea():Rectangle
	{
		return area;
	}

	public function setArea(area:Rectangle):Void 
	{
		this.area = area;
	}
	
	public function getOcupedArea():Rectangle
	{
		return ocupedArea;
	}

	public function setOcupedArea(ocupedArea:Rectangle):Void
	{
		this.ocupedArea = ocupedArea;
	}
	
	public function toString(Void):String
	{
		return "corejuliano.gameelement.Tile";
	}

}